from framwork.common.tools  import open_browsers
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import  Keys
from selenium.webdriver.support.select import Select

"""保存系统设置  选择省市的下拉框"""
#数据
url=r"http://192.168.1.36/crm/index.php?m=user&a=login"
user_name="admin"
passwd="123456"
option1_text="河北省"
option2_text="石家庄市"
#定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_btn_locator=(By.NAME,"submit")
tx_locator=(By.CLASS_NAME,"avatar")
xtsz_locator=(By.LINK_TEXT,"系统设置")
select_sheng_location=(By.CSS_SELECTOR,"#state")
select_qu_location=(By.CSS_SELECTOR,"#city")
save_btn_locator=(By.CSS_SELECTOR,"body > div.container > div.tabbable > div > form > table > tbody > tr:nth-child(16) > td:nth-child(2) > input")
#操作
driver=open_browsers()
driver.get(url)
sleep(1)

driver.find_element(*username_locator).send_keys(user_name)  #登录
driver.find_element(*password_locator).send_keys(passwd)
driver.find_element(*login_btn_locator).click()
sleep(1)
driver.find_element(*tx_locator).click()
driver.find_element(*xtsz_locator).click()
ss_location=driver.find_element(*select_sheng_location)   #选择下拉选项
ss_obj = Select(ss_location)
ss_obj.select_by_visible_text(option1_text)
sq_location=driver.find_element(*select_qu_location)
sq_obj = Select(sq_location)
sq_obj.select_by_visible_text(option2_text)
driver.find_element(*save_btn_locator).click()
sleep(10)
#退出浏览器
sleep(1)
driver.close()